package com.sofly.shiro.factory;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.sofly.dao.group1.IAuthorityDao;

public class FilterChainDefinitionMapBuilder {
	
	@Autowired
	private IAuthorityDao authorityDao;
	
	//从数据库拿出权限的配置要求,包装进builder
	public LinkedHashMap<String, String> buildFilterChainDefinitionMap(){
		LinkedHashMap<String, String> map = new LinkedHashMap<>();
		List<Map<String,String>> maps = authorityDao.getAuthorityMap();
		for (Map<String, String> map2 : maps) {
			String resource = null;
			String authority = null;
			Set<Entry<String,String>> set2 = map2.entrySet();
			for (Entry<String,String> obj : set2) {
				Entry<String,String> entry =  obj;
				if (entry.getKey().equals("resource")) {
					resource = entry.getValue();
				}else{
					authority = entry.getValue();
				}
			}
			map.put(resource, authority);
			
		}
		
//		map.put("/login.jsp", "anon");
//		map.put("/login", "anon");
//		map.put("/logout", "logout");
//		map.put("/js/**", "anon");
//		map.put("/css/**", "anon");
//		map.put("/main.jsp", "authc");
		map.put("/**", "authc");
		
		return map;
	}
	
}
